﻿@using CubicFWNet.Data.ViewModal
@model ReconciliationView
@{
    //ViewBag.Title = "核算查询";
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    var totalMoney = ViewBag.TotalMoney;
}
<section class="content-header">
    <h1>
        采购对账
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("Reconciliation", "Purchase")">采购对账</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdateReconciliation", "Purchase")" method="post">
                    <div class="box-body">
                        @if (null != Model)
                        {
                            <input type="hidden" id="Id" name="Id" value="@Model.Id" />

                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">产品名称</label>
                                <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                    <a href="javascript:void(0)" id="productinfo" data-id="@Model.ProductId">@Model.ProductName</a>
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">采购订单</label>
                                <div class="col-sm-9" style="padding-top: 7px; margin-bottom: 0;">
                                    <a href="javascript:void(0)" id="purchaseinfo" data-id="@Model.PurchaseComposeId">查看</a>
                                </div>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">供应商</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="SupplierName" name="SupplierName" value="@Model.SupplierName" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">发票号</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="FinanceNumber" name="FinanceNumber" placeholder="不开发票的请填0或者不填" value="@Model.FinanceNumber" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">采购数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ShouldAmount" name="ShouldAmount" value="@Model.ShouldAmount" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">合格数量</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ActualAmount" name="ActualAmount" value="@Model.ActualAmount" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">对账总额</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="TotalMoney" name="TotalMoney" value="@totalMoney" readonly="readonly" />
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label class="col-sm-3 control-label">类型</label>
                                @if (Model != null && Model.Status == 1)
                                {
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="ReconciliationTypeStr" name="ReconciliationTypeStr" value="@Model.ReconciliationTypeStr" readonly="readonly" />
                                    </div>
                                }
                                else
                                {
                                    <div class="col-sm-9">
                                        <select class="form-control" name="ReconciliationType" id="ReconciliationType">
                                            <option value="0">预付</option>
                                            <option value="1">月结</option>
                                        </select>
                                    </div>
                                }

                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" id="operationName" name="operationName" value="@Model.CreatorName" readonly="readonly">
                                    }
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    @if (Model.Status == -1)
                                    {
                                        <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                    }
                                    else
                                    {
                                        <input type="text" class="form-control" id="operationTime" name="operationTime" value="@Model.CreateTime.Value.ToString("yyyy-MM-dd")" readonly="readonly">
                                    }
                                </div>
                            </div>
                        }
                    </div>
                    <div class="box-footer" style="width: 80%; margin-left: 20px;">
                        @if (Model != null && Model.Status == -1)
                        {
                            <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">确认</a>
                        }
                        @if (Model != null && Model.Status == 1)
                        {
                            <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmitInfo()">修改</a>
                        }
                        <span id="historyBack" class="btn btn-primary submitbtn">返回</span>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

<style>
    .has-error {
        border-color: #dd4b39;
        box-shadow: none;
    }
</style>


@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#frmedit").validate({
                submitHandler: function (form) {
                    var postData = $(form).formSerialize();
                    $.submitForm({
                        url: $(form).attr("action"),
                        param: postData,
                        success: function () {
                            //$.reload();
                            $.modalAlert("操作成功", "success");
                            window.location.href = '@Url.Action("Reconciliation", "Purchase")';
                        }
                    });
                }
            });
        });

        function formsubmit(t) {
            var financeNumber = $("#FinanceNumber").val();
            if (financeNumber == "") {
                $.modalAlert("请填写发票号", "warning");
                return false;
            }
            $("#frmedit").submit();
        }


        //修改
        function formsubmitInfo() {
            var fid = $("#Id").val();
            var financeNumber = $("#FinanceNumber").val();
            $.ajax({
                url: "/Purchase/UpdateReconciliationAjax",
                type: "post",
                data: {
                    id: fid,
                    financeNumber: financeNumber
                },
                success: function (data) {
                    if (data && JSON.parse(data)) {
                        var d = JSON.parse(data);
                        if (d.Code == 200) {
                            $.modalAlert("修改成功", "success");
                            window.location.reload();
                        } else {
                            $.modalAlert("修改失败", "warning");
                        }
                    } else {
                        $.modalAlert("参数错误", "warning");
                    }
                },
                error: function (xhr, err, state) {
                    //alert("e");
                }
            });
        }

        $("#historyBack").click(function () {
            window.history.go(-1);  //返回上一页
            //window.history.back();  //返回上一页
        });

        $("#productinfo").click(function () {
            var id = $(this).data('id');
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "/Product/Info?PID=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        });
        $("#purchaseinfo").click(function () {
            var id = $(this).data('id');
            var options = {
                id: null,
                title: '产品信息',
                width: "100%",
                height: "100%",
                url: "/Purchase/PurchaseInfoLayout?pcId=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        });
    </script>
}